<template>
  <div style="width: 80% ;margin:0 auto;min-width:921px;">
    <h2 class="margin-bom title">{{title}}</h2>
    <el-button style="display:block" type="primary" @click="toCreate()" v-if="type != 2">新建</el-button>
    <el-table :data="news" :stripe="true">
      <el-table-column type="index" label="序号" width="150"></el-table-column>
      <el-table-column prop="tit" label="题目"></el-table-column>
      <el-table-column prop="con" label="内容"></el-table-column>
      <el-table-column prop="time" label="注册时间"></el-table-column>
      <el-table-column prop label="操作">
        <template slot-scope="scope">
          <el-button type="primary" @click="updateNews(scope.row.id)">查看</el-button>
          <v-del :delId="scope.row.id" @del="del($event)" v-if="type != 2"></v-del>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import ajax from "../../common/js/ajax";
import API from "../../common/js/api";
export default {
  data() {
    return {
      title: "通知列表页",
      news: [],
      // 权限
      type:""
    };
  },
  methods: {
    toCreate() {
      this.$router.push("/index/news/newsCreate");
    },
    updateNews(id) {
      this.$router.push("/index/news/newsCreate?id=" + id);
    },
    del(id) {
      ajax(
        API.delNews,
        "get",
        { id },
        d => {
          this.$message({
            type: "success",
            message: "删除成功"
          });
          this.init();
        },
        err => {
          this.$message({
            type: "warning",
            message: err.data.info
          });
        }
      );
    },
    init() {
      ajax(
        API.findNews,
        "get",
        {},
        d => {
          this.news = d.data.data;
        },
        err => {
          alert(err);
        }
      );
    }
  },
  mounted() {
    this.init();
    this.type = JSON.parse(localStorage.getItem("user")).type;
  }
};
</script>

<style lang="stylus" scoped>
@import '../../common/css/index.styl';
</style>